<template>
  <div class="adjustPost">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item
        :to="{ path: '/employees' }"
      >员工列表</el-breadcrumb-item>
      <el-breadcrumb-item>调岗</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider />
    <div class="header">
      <img
        v-if="positiveList.staffPhoto !== undefined"
        v-err="defaultAvatar"
        style="float:left"
        :src="positiveList.staffPhoto"
        alt=""
        class="img"
      >
      <img
        v-else
        v-err="defaultAvatar"
        style="float:left"
        src="positiveList.staffPhoto"
        alt=""
        class="img"
      >
      <p>
        {{ positiveList.username }}
      </p>
      <div>
        <span>手机<b> {{ positiveList.mobile }}</b></span>
        <span>部门<b>{{ positiveList.departmentName }}</b></span>
      </div>
      <div>
        <span>入职时间<b>{{
          positiveList.timeOfEntry | formatDate('yyyy-MM-dd')
        }}</b></span>
      </div>
    </div>
    <el-divider />
    <!-- 基础信息 -->
    <el-form label-width="220px">
      <div class="block">
        <el-form-item label="岗位:">
          <el-input
            v-model="formData.post"
            placeholder="请输入"
            class="inputW"
            style="width: 28%;"
          />
        </el-form-item>
        <el-form-item label="职级:">
          <el-input
            v-model="formData.rank"
            class="inputW"
            style="width: 28%;"
            placeholder="请输入"
          />
        </el-form-item>

        <el-form-item label="汇报对象:">
          <el-select
            v-model="formData.reportId"
            filterable
            placeholder="请选择"
            class="inputW"
          >
            <el-option
              v-for="item in depts"
              :key="item.id"
              :label="item.username"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="HRBP:">
          <el-select
            v-model="formData.hrbp"
            filterable
            placeholder="请选择"
            class="inputW"
          >
            <el-option
              v-for="item in depts"
              :key="item.id"
              :label="item.username"
              :value="item.id"
              class="inputW"
            />
          </el-select>
        </el-form-item>
        <el-form-item class="formInfo" label="调岗时间：">
          <el-date-picker
            v-model="formData.adjustmentTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="调岗原因:">
          <el-input
            v-model="formData.causeOfAdjustingPost"
            type="textarea"
            placeholder="1-300位字符"
          />
        </el-form-item>
        <el-form-item label="现合同开始时间:">
          <el-date-picker
            v-model="formData.currentContractStartTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="现合同结束时间:">
          <el-date-picker
            v-model="formData.closingTimeOfCurrentContract"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="工作地点:">
          <el-input
            v-model="formData.workingPlace"
            placeholder="请输入"
            class="inputW"
            style="width: 28%;"
          />
        </el-form-item>
        <el-form-item label="首次合同开始时间:">
          <el-date-picker
            v-model="formData.initialContractStartTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="首次合同结束时间:">
          <el-date-picker
            v-model="formData.firstContractTerminationTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>

        <el-form-item label="续签次数:">
          <el-select v-model="formData.renewalNumber" class="filter-item">
            <el-option
              v-for="item in EmployeeEnum.renewalCount"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="推荐企业/人:">
          <el-input
            v-model="formData.recommenderBusinessPeople"
            placeholder="请输入"
            class="infoPosition inputW"
            style="width: 28%;"
          />
        </el-form-item>
      </div>
    </el-form>
    <div slot="footer" style="text-align: center" class="dialog-footer">
      <el-button @click="$router.back()">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import defaultAvatar from '@/assets/common/headPortrait.png'
import {
  getEssentialById,
  getTransferPosition,
  updTransferPosition
} from '@/api/employee'
import EmployeeEnum from '@/api/constant/employees'

export default {
  name: 'AdjustPost',
  components: {},
  data() {
    return {
      depts: [],
      userId: this.$route.params.id,
      positiveList: {},
      defaultAvatar,
      EmployeeEnum,
      formData: {
        post: '', // 岗位
        rank: null, // 职级
        reportId: '', // 汇报对象
        hrbp: '', // HRBP
        adjustmentTime: '', // 调岗时间
        causeOfAdjustingPost: '', // 调岗原因
        currentContractStartTime: '', // 现合同开始时间
        closingTimeOfCurrentContract: '', // 现合同结束时间
        workingPlace: '', // 工作地点
        initialContractStartTime: '', // 首次合同开始时间
        firstContractTerminationTime: '', // 首次合同结束时间
        contractPeriod: '', // 合同期限
        renewalNumber: '', // 续签次数
        recommenderBusinessPeople: '' // 推荐企业人
      }
    }
  },
  async created() {
    // 个人信息
    const res = await getEssentialById({ id: this.userId })
    this.positiveList = res
    // 调岗信息
    const resRes = await getTransferPosition(this.userId)
    this.formData = resRes
  },
  methods: {
    // 确认的点击事件
    async confirm() {
      await updTransferPosition(this.formData)
      this.$message.success('保存成功')
    }
  }
}
</script>

<style lang="scss">
.adjustPost {
  padding: 30px 20px;
  background-color: #fff;
  border-radius: 5px;
  .el-breadcrumb {
    margin-bottom: 15px;
    .el-breadcrumb__inner.is-link:hover {
      color: #00a6a6;
    }
  }
  .header {
    margin-top: 40px;
    margin-left: 80px;
    height: 130px;
    line-height: 26px;
    p {
      margin: 0;
      font-weight: 700;
    }
    span {
      padding-right: 15px;
      color: #999999;
      b {
        padding-left: 5px;
        color: #606266;
        font-weight: normal;
      }
    }
    img {
      width: 100px;
      margin-right: 20px;
      height: 100px;
      border-radius: 50%;
    }
  }
  .el-divider--horizontal {
    margin: 0 0 18px 0;
  }
  .el-textarea {
    width: 64%;
  }
}
</style>
